From 97ff064f22cdfef8abf620eb6900da6163e9b734 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Mon, 22 Oct 2001 12:59:21 +0000 Subject: [PATCH] Add a function, gdk_threads_init() that must be explicitely called to Mon Oct 22 08:51:02 2001 Owen Taylor * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: Add a function, gdk_threads_init() that must be explicitely called to enable the GDK thread mutex. --- ChangeLog | 6 ++++++ ChangeLog.pre-2-0 | 6 ++++++ ChangeLog.pre-2-10 | 6 ++++++ ChangeLog.pre-2-2 | 6 ++++++ ChangeLog.pre-2-4 | 6 ++++++ ChangeLog.pre-2-6 | 6 ++++++ ChangeLog.pre-2-8 | 6 ++++++ docs/Changes-2.0.txt | 11 +++++++++++ gdk/gdk.c | 23 ++++++++++++++++++++--- gdk/gdk.h | 1 + 10 files changed, 74 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78c3c2e92d..3efdfcedaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Oct 22 08:51:02 2001 Owen Taylor + + * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: + Add a function, gdk_threads_init() that must be explicitely + called to enable the GDK thread mutex. + 2001-10-22 Jakub Steiner * gtk/stock-icons/stock_stop.png: no body parts diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 78c3c2e92d..3efdfcedaa 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +Mon Oct 22 08:51:02 2001 Owen Taylor + + * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: + Add a function, gdk_threads_init() that must be explicitely + called to enable the GDK thread mutex. + 2001-10-22 Jakub Steiner * gtk/stock-icons/stock_stop.png: no body parts diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 78c3c2e92d..3efdfcedaa 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +Mon Oct 22 08:51:02 2001 Owen Taylor + + * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: + Add a function, gdk_threads_init() that must be explicitely + called to enable the GDK thread mutex. + 2001-10-22 Jakub Steiner * gtk/stock-icons/stock_stop.png: no body parts diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 78c3c2e92d..3efdfcedaa 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +Mon Oct 22 08:51:02 2001 Owen Taylor + + * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: + Add a function, gdk_threads_init() that must be explicitely + called to enable the GDK thread mutex. + 2001-10-22 Jakub Steiner * gtk/stock-icons/stock_stop.png: no body parts diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 78c3c2e92d..3efdfcedaa 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +Mon Oct 22 08:51:02 2001 Owen Taylor + + * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: + Add a function, gdk_threads_init() that must be explicitely + called to enable the GDK thread mutex. + 2001-10-22 Jakub Steiner * gtk/stock-icons/stock_stop.png: no body parts diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 78c3c2e92d..3efdfcedaa 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +Mon Oct 22 08:51:02 2001 Owen Taylor + + * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: + Add a function, gdk_threads_init() that must be explicitely + called to enable the GDK thread mutex. + 2001-10-22 Jakub Steiner * gtk/stock-icons/stock_stop.png: no body parts diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 78c3c2e92d..3efdfcedaa 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +Mon Oct 22 08:51:02 2001 Owen Taylor + + * gdk/gdk.[ch] (gdk_threads_init) docs/Changes-2.0.txt: + Add a function, gdk_threads_init() that must be explicitely + called to enable the GDK thread mutex. + 2001-10-22 Jakub Steiner * gtk/stock-icons/stock_stop.png: no body parts diff --git a/docs/Changes-2.0.txt b/docs/Changes-2.0.txt index adf01fb299..01e0c5c75d 100644 --- a/docs/Changes-2.0.txt +++ b/docs/Changes-2.0.txt @@ -494,3 +494,14 @@ Incompatible Changes from GTK+-1.2 to GTK+-2.0: * The default selected day for GtkCalendar is now the current day in the month, not the first day in the month. The current month and year were already used. + +* GDK is no longer put into threaded mode automatically when + g_thread_init() has been called. In order to use the + global GDK thread mutex with gdk_threads_enter() and + gdk_threads_leave(), you must call gdk_threads_init() explicitely. + gdk_threads_init() calls g_thread_init() if it hasn't already + been called, so you can typically change your call to g_thread_init() + into a call to gdk_threads_init(). + + If you aren't using GDK and GTK+ functions from multiple threads, + there is no reason to call gdk_threads_init(). diff --git a/gdk/gdk.c b/gdk/gdk.c index bae902dbcc..22d13bde86 100644 --- a/gdk/gdk.c +++ b/gdk/gdk.c @@ -279,9 +279,6 @@ gdk_init_check (int *argc, if (gdk_initialized) return TRUE; - if (g_thread_supported ()) - gdk_threads_mutex = g_mutex_new (); - if (argc && argv) { argc_orig = *argc; @@ -514,6 +511,26 @@ gdk_threads_leave () GDK_THREADS_LEAVE (); } +/** + * gdk_threads_init: + * + * Initializes GDK so that it can be used from multiple threads + * in conjunction with gdk_threads_enter() and gdk_threads_leave(). + * If g_thread_init() has not yet been called, calls + * g_thread_init(NULL). + * + * This call must be made before any use of the main loop from + * GTK+; to be safe, call it before gtk_init(). + **/ +void +gdk_threads_init () +{ + if (!g_thread_supported ()) + g_thread_init (NULL); + + gdk_threads_mutex = g_mutex_new (); +} + G_CONST_RETURN char * gdk_get_program_class (void) { diff --git a/gdk/gdk.h b/gdk/gdk.h index 5546278349..308130fb07 100644 --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -151,6 +151,7 @@ GDKVAR GMutex *gdk_threads_mutex; void gdk_threads_enter (void); void gdk_threads_leave (void); +void gdk_threads_init (void); #ifdef G_THREADS_ENABLED # define GDK_THREADS_ENTER() G_STMT_START { \ -- 2.30.2